package edu.neusoft.yuejian_09.model;

import edu.neusoft.yuejian_09.base.Constant;
import edu.neusoft.yuejian_09.base.RetrofitBaseModel;
import edu.neusoft.yuejian_09.base.RetrofitListener;
import edu.neusoft.yuejian_09.bean.Comment;
import edu.neusoft.yuejian_09.service.CommentService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by 爽 on 2017/10/23.
 */

public class CommentModel  extends RetrofitBaseModel {
    private int flag=1;
    public CommentService commentService;
    public CommentModel(){
        this.commentService=retrofit.create(CommentService.class);
    }
    //获取评论列表
    public void getCommentsById(int Show_id, final RetrofitListener listener){
        Call call=commentService.getCommentsByShow(Show_id);
        bindCallback(call,listener, Constant.COMMENT);
    }

    //发布评论
    public void insertNote(int user_id,int master_id,String c_content, final RetrofitListener listener){
        CommentService commentService=retrofit.create(CommentService.class);
        Call call=commentService.insertNote(user_id,master_id,c_content);
        Callback<Comment> callback=new Callback<Comment>(){
            @Override
            public void onResponse(Call<Comment> call, Response<Comment> response ){
                Comment data=response.body();
                listener.onSuccess(data,flag);
            }
            @Override
            public  void onFailure(Call<Comment> call, Throwable t){
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
}
